﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Threading;
using PMSGSC.Common;
using PMSGSC.BLL;
using PMSGSC.DAL;

namespace PMSGSC.App
{
    public partial class frmLogin : DevExpress.XtraEditors.XtraForm
    {
        public frmLogin()
        {
            InitializeComponent();
            LoadSkin();
            txtID.Focus();
        }
        public static void ThreadProc()
        {
            Application.Run(new frmCopyRight());
        }
        private static void LoadSkin()
        {
            DevExpress.Skins.SkinManager.EnableFormSkins();
            DevExpress.UserSkins.BonusSkins.Register();
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.LookAndFeel.DefaultLookAndFeel obj = new DevExpress.LookAndFeel.DefaultLookAndFeel();
            try
            {
                LookAndFeelSettings.Load("LookAndFeelSettings.dat");
            }
            catch
            {
                obj.LookAndFeel.SetSkinStyle("Blue");
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtID.EditValue != null && txtPassword.EditValue != null)
            {
                Employee result = Employee_BLL.TestLogin(txtID.EditValue.ToString(), txtPassword.EditValue.ToString());
                if (result != null)
                {
                    frmMain.UserLogin = result;
                    Thread thread = new Thread(new ThreadStart(ThreadProc));
                    thread.Start();
                    this.Close();
                }
            }
        }
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Enter))
            {
                btnLogin.PerformClick();
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void frmLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            LookAndFeelSettings.Save("LookAndFeelSettings.dat");
        }
    }
}